<?php

include_once ('global.php');

if (empty($_GET[cid]))
    exit();

/**
 * 指定长度的字符串截取
 * @param type $str
 * @param type $len
 * @return type
 */
function sub($str, $len) {
    $i = 0;
    while ($i < $len) {

        if (ord($str[$i]) > 128) {
            $i = $i + 2;
        }
        $i++;
    }
    return substr($str, 0, $i) . "...";
}

$sql = "SELECT * FROM `p_newsclass` where f_id=0 order by id DESC";
$query = $db->query($sql);
while ($row_class = $db->fetch_array($query)) {
    $sm_class[] = array(
        "name" => $row_class[name],
        "id" => $row_class[id]
    );
}
$smarty->assign("sm_class", $sm_class); //��������
//==============

$sql = "SELECT * FROM p_config";
$query = $db->query($sql);
while ($row_config = $db->fetch_array($query)) {
    $sm_config[] = $row_config[values];
}

$smarty->assign("sm_config", $sm_config); //��������
//==============
$query = $db->findall("p_newsclass");
while ($row = $db->fetch_array($query)) {
    $news_class_arr[$row[id]] = $row[name];
}

$classname = $news_class_arr[$_GET[cid]];


$result = mysql_query("select id from p_newsbase where cid ='$_GET[cid]'");
$total = mysql_num_rows($result);
pageft($total, 18);
if ($firstcount < 0)
    $firstcount = 0;
$sql = "SELECT * FROM `p_newsbase` where cid='$_GET[cid]' order by id DESC limit $firstcount, $displaypg";
$query = $db->query($sql);
while ($row_news = $db->fetch_array($query)) {
    $sql = "select `diu_place`,`name`from p_newsbase as a, p_newscontent as b where a.id=b.nid and a.id='$row_news[id]'";
    $query = mysql_query($sql);
    $row_newsweibo = mysql_fetch_array($query);
    if (strlen($row_news[title]) > 27) {
        $row_news[title] = sub($row_news[title], 27);
    }
    if (strlen($row_news[keyword]) > 80) {
        $row_news[keyword] = sub($row_news[keyword], 80);
    }
    $sm_list[] = array("title" => $row_news[title], "id" => $row_news[id], "keyword" => $row_news[keyword], "time" => date("Y-m-d", $row_news[date_time]), "didian" => $row_newsweibo[diu_place], "classname" => $classname, "name" => $row_newsweibo[name]);
}
//�=====================================
$query = mysql_query("SELECT `id` , `f_id` , `name` FROM `p_newsclass` WHERE `f_id` =$_GET[cid]");

while ($row = mysql_fetch_array($query)) {
    $lei[] = array("name" => $row[name], "id" => $row[id]);
}
//===================================================
$smarty->assign("lei", $lei); //����б�
$smarty->assign("number", $number); //����ͳ��
$smarty->assign("sm_list", $sm_list); //�����б�
$smarty->assign("pagenav", $pagenav); //���ŷ�ҳ
$smarty->display("list_test.htm");



/* $query = $db->findall("p_newsclass");
  while ($row = $db->fetch_array($query)) {
  $news_class_arr[$row[id]] = $row[name];
  }
  $classname=$news_class_arr[$_GET[cid]];
  $query = $db->findall("p_newsclass where f_id='$_GET[cid]'");
  while ($row = $db->fetch_array($query)) {
  $news_class_in.= $row[id].",";
  $news_class_list_arr[] =array("name"=>$row[name],"id"=>$row[id],);
  }

  $news_class_in=$news_class_in."$_GET[cid]";

  $result = mysql_query("select id from p_newsbase where cid in ($news_class_in)");
  $total = mysql_num_rows($result);
  pageft($total, 14);
  if ($firstcount < 0)
  $firstcount = 0;
  $query = $db->findall("p_newsbase where cid in ($news_class_in) ORDER BY `id` DESC limit  $firstcount, $displaypg");
  while ($row = $db->fetch_array($query)) {
  $sm_list[] = array (
  "cid" => $row[cid],
  "cidname" => $news_class_arr[$row[cid]],
  "title" => $row[title],
  "id" => $row[id],
  "date_time" => date("Y-m-d",$row[date_time]),
  "keyword"=>$row_news[keyword]);
  }
  $smarty->assign("sm_list", $sm_list); //�����б�
  $smarty->assign("pagenav", $pagenav); //���ŷ�ҳ
  $smarty->assign("news_class_list_arr", $news_class_list_arr); //��������

  $sql="SELECT * FROM `p_newsbase` order by id ASC limit 8";
  $query=$db->query($sql);
  while($row_news=$db->fetch_array($query)){
  $sm_news[]=array("title"=>$row_news[title],"id"=>$row_news[id],"keyword"=>$row_news[keyword], "time"=> date("Y-m-d",$row_news[date_time]));
  }
  $smarty->assign("classname",$classname);
  $smarty->assign("sm_news",$sm_news);
  $smarty->display("list.htm");
 */
?>
